package com.xy.servicemanage.request;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import com.xy.common.util.Configure;

public class HttpSender {

	private static String queryUrl = Configure.getProperty("backURL")
			+ "/query";
	private static String notifyUrl = Configure.getProperty("frontURL")
			+ "/notify";

	public static void query(long rid) {
		send(queryUrl, rid);
	}

	public static void notify(long rid) {
		send(notifyUrl, rid);
	}

	public static void send(String u, long rid) {
		try {
			String data = URLEncoder.encode("rid=" + rid, "UTF-8");
			URL url = new URL(u + "?rid=" + rid);
			URLConnection conn = url.openConnection();
			conn.setDoOutput(true);
			conn.setRequestProperty("User-Agent", "MSIE");
			conn.connect();
			/*
			 * OutputStreamWriter wr = new OutputStreamWriter(
			 * conn.getOutputStream()); wr.write(data); wr.flush();
			 */
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					conn.getInputStream()));
			String line;
			StringBuffer sb = new StringBuffer();
			while ((line = rd.readLine()) != null) {
				sb.append(line);
			}
			// wr.close();
			rd.close();
			// return sb.toString();*/
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// return "error";
	}

	public static void main(String args[]) {
		notify(19);
		query(19);
	}

}
